<extend name="Base/common"/>
<block name="TITLE"><title>世果价目表</title></block>
<block name="body">
    <header data-am-widget="header" class="am-header am-header-default am-header-fixed">
        <div class="am-header-left am-header-nav">
            <a href="{:U('index/index')}" class="">
                <i class="am-header-icon am-icon-home"></i>
            </a>
        </div>
        <h1 class="am-header-title">
            <a href="#title-link" class="">
               &nbsp;{$title}
            </a>
        </h1>
        <div class="am-header-right am-header-nav">

        </div>
           <nav data-am-widget="menu" class="am-menu  am-menu-offcanvas2" data-am-menu-offcanvas>
        <a href="javascript: void(0)" class="am-menu-toggle">
            <i class="am-menu-toggle-icon am-icon-bars"></i>
        </a>
        <div class="am-offcanvas">
            <div class="am-offcanvas-bar am-offcanvas-bar-flip">
                <ul class="am-menu-nav am-avg-sm-3">
                    <li class="">
                        <a href="?" class="am-active">全部</a>
                    </li>
                    <volist name="label" id="labellist">
                        <li >
                            <a href="?label={$key}&chinese={$labellist}" class="">{$labellist}</a>
                        </li>
                    </volist>
                </ul>
            </div>
        </div>
    </nav>
    </header>
    <div>        
        <table class="am-table am-table-bordered am-table-radius am-table-striped " style='text-align: center;' >
            <thead>
                <tr >
                    <th style='text-align: center;'>商品</th>
                    <th style='text-align: center;'>产地</th>
                    <th style='text-align: center;'>规格</th>
                    <th style='min-width: 50px;'>单价</th>
                    <th style='text-align: center;'></th>
                </tr>
            </thead>
            <tbody class="" >

                <volist name="pricelist" id="list" key='i'>
                    <tr>
                        <td>{$list.name}</td>
                        <td>{$list.origin}</td>
                        <td>{$list.quantity}</td>
                        <td>{$list.price}</td>
                        <td>
                            <if condition="strpos($list['tagarray'],'SINGLE') gt -1">
                                <a href="{:U('BuyNow/add',array('id'=>$list['id']))}"><span class="am-btn am-btn-success" >立即购买</span></a>
                                <else/>
                                <if condition="($list.inventory lt 0)OR($list.inventory eq 0)">
                                         <span class="am-btn am-btn-warning" >正在补货</span>
                                <else/>
                                        <if condition="($list.iscart eq false)">
                                            <button id="{$list.id}" class="am-btn am-btn-danger dinggou"  onclick="addGoods(this);" >加购物车</button>
                                                <button id="del_{$list.id}" class="am-btn am-btn-primary cancle"  onclick="delGoods(this);" style="display: none;">取消订购</button>
                                            <else/>
                                                <button id="{$list.id}" class="am-btn  am-btn-danger dinggou"  onclick="addGoods(this);" style="display: none;">加购物车</button>
                                                <button id="del_{$list.id}" class="am-btn am-btn-primary cancle"  onclick="delGoods(this);"  >取消订购</button>
                                        </if>
                                </if>
                            </if>
                       </td>
                    </tr>
                </volist>
            </tbody>
        </table>
    </div>  
    <script>   
        //$('.dinggou').show();
        //$('.cancle').hide();        
        function cancel()
        {
            if(confirm("确定要取消订购吗？")){
                return true;
            }else{
                return false;
            }
        }
        
        var addGoods = function(o){
            var pid = $(o).attr('id');   
            $('#'+pid).hide();
            $('#del_'+pid).show();
            var url = "{:U('Pricelist/addToCart')}";
            var params = "pid="+pid;
            $.ajax({
                method:'post',
                url:url,
                data:params,
                success:function(obj){                
                    if(obj){
                        //alert("订购成功");   
                        
                        
                    }                    
                },
                error:function(obj){
                    alert("订购失败");                    
                }
            });            
        };
        var delGoods = function(o){
            var pid1 = $(o).attr('id'); 
            var pid2=pid1.split('_');
            var pid=pid2[1];
            $('#'+pid1).hide();
            $('#'+pid).show();
            
            var url = "{:U('Pricelist/delFromCart')}";
            var params = "pid="+pid;
            $.ajax({
                method:'post',
                url:url,
                data:params,
                success:function(obj){                       
                    if(obj===1){
                       // alert("取消订购成功");                       
                    }                    
                },
                error:function(obj){
                    alert("取消订购失败");
                }
            });            
        };
        $(function(){
            
        });
    </script>
</block>

